package com.emoji;

import java.util.regex.Pattern;

public class EmojiUtil {

    // private static final String REG =
    // "[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]";

    private static final Pattern P_EMOJI = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]", Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
    private static final String EMPTY = "";

    /**
     * 过滤emoji
     */
    public static String filterEmoji(String source) {
        return filterEmoji(source, EMPTY);
    }

    public static String filterEmoji(String source, String replacement) {
        if (source == null || source.isEmpty()) {
            return source;
        }
        return P_EMOJI.matcher(source).replaceAll(replacement);
    }

    /**
     * 是否包含Emoji
     */
    public static boolean containsEmoji(String source) {
        if (source == null || source.isEmpty()) {
            return false;
        }
        return P_EMOJI.matcher(source).matches();
    }
}
